﻿using System;
using System.Globalization;
using System.Text.RegularExpressions;

namespace UFIDA.U8.BJSOFT.LF.MES.WEBAPI.Method
{
	// Token: 0x02000014 RID: 20
	public class PublicMet
	{
		/// <summary>
		/// 判断字符串是否可以转化为数字
		/// </summary>
		/// <param name="str">要检查的字符串</param>
		/// <returns>true:可以转换为数字；false：不是数字</returns>
		// Token: 0x0600006E RID: 110 RVA: 0x00006C68 File Offset: 0x00004E68
		public static bool IsNumberic(string str)
		{
			double vsNum;
			return double.TryParse(str, NumberStyles.Float, NumberFormatInfo.InvariantInfo, out vsNum);
		}

		/// <summary>
		/// 转换为float类型是否成功
		/// </summary>
		/// <param name="s"></param>
		/// <returns></returns>
		// Token: 0x0600006F RID: 111 RVA: 0x00006C90 File Offset: 0x00004E90
		public static bool StringToFloat(string s)
		{
			float f = 0f;
			return float.TryParse(s, out f);
		}

		/// <summary>
		/// 校验特殊字符
		/// </summary>
		/// <param name="str"></param>
		/// <returns></returns>
		// Token: 0x06000070 RID: 112 RVA: 0x00006CB4 File Offset: 0x00004EB4
		public static bool IsSpecialChar(string str)
		{
			Regex regExp = new Regex("[^0-9a-zA-Z一-龥]");
			return regExp.IsMatch(str);
		}

		// Token: 0x06000071 RID: 113 RVA: 0x00006CE4 File Offset: 0x00004EE4
		public static string setvalue(int zdlx, string zd)
		{
			string newzd = zd;
			bool flag = zdlx == 1;
			if (flag)
			{
				bool flag2 = string.IsNullOrEmpty(zd);
				if (flag2)
				{
					newzd = "0";
				}
			}
			bool flag3 = zdlx == 2;
			if (flag3)
			{
				bool flag4 = string.IsNullOrEmpty(zd);
				if (flag4)
				{
					newzd = "NULL";
				}
				else
				{
					newzd = "'" + zd + "'";
				}
			}
			return newzd;
		}

		/// <summary>
		/// 创建一个按时间排序的Guid
		/// </summary>
		/// <returns></returns>
		// Token: 0x06000072 RID: 114 RVA: 0x00006D44 File Offset: 0x00004F44
		public static string GetID()
		{
			byte[] guidArray = Guid.NewGuid().ToByteArray();
			DateTime now = DateTime.Now;
			DateTime baseDate = new DateTime(1900, 1, 1);
			TimeSpan days = new TimeSpan(now.Ticks - baseDate.Ticks);
			TimeSpan msecs = new TimeSpan(now.Ticks - new DateTime(now.Year, now.Month, now.Day).Ticks);
			byte[] daysArray = BitConverter.GetBytes(days.Days);
			byte[] msecsArray = BitConverter.GetBytes((long)(msecs.TotalMilliseconds / 3.333333));
			Array.Copy(daysArray, 0, guidArray, 2, 2);
			Array.Copy(msecsArray, 2, guidArray, 0, 2);
			Array.Copy(msecsArray, 0, guidArray, 4, 2);
			return new Guid(guidArray).ToString();
		}

		/// <summary>
		/// 是否邮箱
		/// </summary>
		/// <param name="value">邮箱地址</param>
		/// <param name="isRestrict">是否按严格模式验证</param>
		/// <returns></returns>
		// Token: 0x06000073 RID: 115 RVA: 0x00006E24 File Offset: 0x00005024
		public static bool IsEmail(string value, bool isRestrict = false)
		{
			bool flag = string.IsNullOrEmpty(value);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				string pattern = isRestrict ? "^(?(\")(\".+?\"@)|(([0-9a-zA-Z]((\\.(?!\\.))|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[0-9a-zA-Z])@))(?(\\[)(\\[(\\d{1,3}\\.){3}\\d{1,3}\\])|(([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,6}))$" : "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
				result = Regex.IsMatch(value, pattern);
			}
			return result;
		}

		/// <summary>
		/// 是否存在邮箱
		/// </summary>
		/// <param name="value">值</param>
		/// <param name="isRestrict">是否按严格模式验证</param>
		/// <returns></returns>
		// Token: 0x06000074 RID: 116 RVA: 0x00006E5C File Offset: 0x0000505C
		public static bool HasEmail(string value, bool isRestrict = false)
		{
			bool flag = string.IsNullOrEmpty(value);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				string pattern = isRestrict ? "^(?(\")(\".+?\"@)|(([0-9a-zA-Z]((\\.(?!\\.))|[-!#\\$%&'\\*\\+/=\\?\\^`\\{\\}\\|~\\w])*)(?<=[0-9a-zA-Z])@))(?(\\[)(\\[(\\d{1,3}\\.){3}\\d{1,3}\\])|(([0-9a-zA-Z][-\\w]*[0-9a-zA-Z]\\.)+[a-zA-Z]{2,6}))$" : "^[\\w-]+(\\.[\\w-]+)*@[\\w-]+(\\.[\\w-]+)+$";
				result = Regex.IsMatch(value, pattern);
			}
			return result;
		}

		/// <summary>
		/// 是否为日期型字符串
		/// </summary>
		/// <param name="StrSource">日期字符串(2008-05-08)</param>
		/// <returns></returns>
		// Token: 0x06000075 RID: 117 RVA: 0x00006E94 File Offset: 0x00005094
		public static bool IsDate(string StrSource)
		{
			return Regex.IsMatch(StrSource, "^((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-9]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-))$");
		}

		/// <summary>
		/// 是否为时间型字符串
		/// </summary>
		/// <param name="source">时间字符串(15:00:00)</param>
		/// <returns></returns>
		// Token: 0x06000076 RID: 118 RVA: 0x00006EB4 File Offset: 0x000050B4
		public static bool IsTime(string StrSource)
		{
			return Regex.IsMatch(StrSource, "^((20|21|22|23|[0-1]?\\d):[0-5]?\\d:[0-5]?\\d)$");
		}

		/// <summary>
		/// 是否为日期+时间型字符串
		/// </summary>
		/// <param name="source"></param>
		/// <returns></returns>
		// Token: 0x06000077 RID: 119 RVA: 0x00006ED4 File Offset: 0x000050D4
		public static bool IsDateTime(string StrSource)
		{
			return Regex.IsMatch(StrSource, "^(((((1[6-9]|[2-9]\\d)\\d{2})-(0?[13578]|1[02])-(0?[1-9]|[12]\\d|3[01]))|(((1[6-9]|[2-9]\\d)\\d{2})-(0?[13456789]|1[012])-(0?[1-9]|[12]\\d|30))|(((1[6-9]|[2-9]\\d)\\d{2})-0?2-(0?[1-9]|1\\d|2[0-8]))|(((1[6-9]|[2-9]\\d)(0[48]|[2468][048]|[13579][26])|((16|[2468][048]|[3579][26])00))-0?2-29-)) (20|21|22|23|[0-1]?\\d):[0-5]?\\d:[0-5]?\\d)$ ");
		}

		public static string CUSERNAME(string cuserid)
        {
			return cuserid;
			//return DBHelp.SQLHelper.GetString("select cUser_Name from UFSystem..UA_User where cuser_id='" + cuserid+"'");
        }
	}
}
